package com.lanhai.longheng.dispatch;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

import com.lanhai.longheng.beans.DeviceBean;
import com.lanhai.longheng.interfaces.IAgv;
import com.lanhai.longheng.interfaces.IControlArea;
import com.lanhai.longheng.interfaces.IDevice;
import com.lanhai.longheng.interfaces.IDeviceMount;
import com.lanhai.longheng.interfaces.IDot;
import com.lanhai.longheng.interfaces.IPower;
import com.lanhai.longheng.interfaces.ITempData;
import com.lanhai.longheng.localized.LHRoadMap;

@EnableAsync
@Service
public class DispatchHack {
	@Autowired
	IControlArea iControlArea;
	
	@Autowired
	IDevice iDevice;
	
	@Autowired
	ITempData iTempData;
	
	@Autowired
	IPower iPower;
	
	@Autowired
	IDot iDot;
	
	@Autowired
	IDeviceMount iDeviceMount;
		
	@Autowired
	IAgv iAgv;
	
	@Autowired
	LHRoadMap lhmap;
	
	@Async("agvExecutor") 
	public  void releaseControllerArea(long areaid) {
		//交管区解锁
		iControlArea.unlockArea(areaid);
	}
	
	@Async("agvExecutor") 
	public  void releaseDevice(int deviceid ) {
		//机台解锁
		iDevice.unlockDeviceById(deviceid);
		 
		DeviceBean deviceBean=iDevice.getDaoByID(deviceid);
		//点位重置
		if(deviceBean!=null) {
			iTempData.setDotOfAgv(deviceBean.getDotNO(), 0);
		}
	}
	
	
	
	/**
	 * 重置交管区基础数据
	 * @param areaid
	 */
	@Async("agvExecutor") 
	public  void reloadControllerArea( ) {
		//交管区解锁
		iControlArea.clearArea();
	}
	
	/**
	 * 重置点位数据
	 * @param areaid
	 */
	@Async("agvExecutor") 
	public  void reloadDot( ) {
		//交管区解锁
		iDot.clearDot();  
	}
	
	/**
	 * 释放充电桩
	 * @param areaid
	 */
	@Async("agvExecutor") 
	public  void releasePower(long id) {
		//交管区解锁
		iPower.unlockPowerByID(id);
	}
	
	@Async("agvExecutor") 
	public  void fullDeviceMount(long id) {
		//填充设备装料情况
		 iDeviceMount.fullDeviceMount(id);
	}
	
	@Async("agvExecutor") 
	public  void emptyDeviceMount(long id) {
		//清空设备装料情况
		 iDeviceMount.clear(id);
	}
 
	@Async("agvExecutor") 
	public void releaseKS() {
		lhmap.ksZero();
	}
	
	@Async("agvExecutor") 
	public void releaseZR() {
		lhmap.zrZero();
	}
	
	@Async("agvExecutor") 
	public void releaseAgv(int agvid) {
		iAgv.reset(agvid);
	}
}
